package common

import (
	"database/sql/driver"
	"fmt"
	"strconv"
	"time"
)

type LocalTime time.Time

func (l *LocalTime) MarshalJSON() ([]byte, error) {
	tTime := time.Time(*l)
	return []byte(fmt.Sprintf("\"%v\"", tTime.Format("2006-01-02 15:04:05"))), nil
}
func (l *LocalTime) UnmarshalJSON(t []byte) error {
	unquote, err := strconv.Unquote(string(t))
	if err != nil {
		return err
	}
	parse, err := time.Parse("2006-01-02 15:04:05", unquote)
	if err != nil {
		return err
	}
	*l = LocalTime(parse)
	return nil
}
func (l LocalTime) Value() (driver.Value, error) {
	var zeroTime time.Time
	tlt := time.Time(l)
	//判断给定时间是否和默认零时间的时间戳相同
	if tlt.UnixNano() == zeroTime.UnixNano() {
		return nil, nil
	}
	return tlt, nil
}
func (l *LocalTime) Scan(v interface{}) error {
	if value, ok := v.(time.Time); ok {
		*l = LocalTime(value)
		return nil
	}
	return fmt.Errorf("can not convert %v to timestamp", v)
}

type AllCommonStruct struct {
	Id        int        `gorm:"primaryKey;autoIncrement;" json:"id"`
	StatusCd  string     `gorm:"size:1;default:1;comment:0-禁用,1-启用;" json:"statusCd"`
	CreatedAt *LocalTime `gorm:"autoCreateTime:milli;comment:创建时间;" json:"createdAt"`
	UpdatedAt *LocalTime `gorm:"autoUpdateTime:milli;comment:更新时间;" json:"updatedAt"`
}

const BASEURL = "http://qigeyu.fun"
const SECRET = "Wsyya928!!@@&&**"
